package ui.patient_card.view;

import database.dao.DaoFactory;
import database.dao.SurveyDao;
import patient.Patient;
import ui.patient_card.controller.PatientCardController;
import ui.patient_card.models.SurveyTableModel;

import javax.swing.*;

public class LeftTablePanel extends JPanel {
    PatientCardController presenter = PatientCardController.getInstance();

    SurveyDao surveyDao = new SurveyDao(new DaoFactory());

    public LeftTablePanel(Patient patient) {
        initComponents(patient);
    }

    private void initComponents(Patient patient) {
        SurveyTableModel surveyTableModel = new SurveyTableModel(patient, surveyDao.getAllSurveysByPatient(patient));

        JTable patientCardTable = new JTable(surveyTableModel);
        patientCardTable.setRowSelectionAllowed(false);
        patientCardTable.setAutoCreateRowSorter(true);

        JScrollPane paneWithTable = new JScrollPane(patientCardTable);
        add(paneWithTable);

        presenter.setSurveyTableModel(surveyTableModel);
        presenter.setSurveyTable(patientCardTable);
    }
}
